package movee.resilience4j;


import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 *
 * @author movee
 */
@Slf4j
@SpringBootApplication
public class Resilience4jApplication {

    public static void main(String[] args) {
        SpringApplication.run(Resilience4jApplication.class, args);
    }

    @Bean
    @SuppressWarnings("unchecked")
    public CommandLineRunner runner(CircuitBreakerRegistry circuitBreakerRegistry,
                                    CircuitBreakerExam cbExam,
                                    RetryExam retryExam) {

        return (args) -> {

            try {
                log.debug("=====begin Resilience4jApplication runner");

                // cbExam.decorateInvoke();
                // cbExam.aopInvoke();

                // retryExam.test();

                log.debug("=====finish Resilience4jApplication runner");
            } catch (Throwable t) {
                log.error("====={}", ExceptionUtils.getStackTrace(t));
            }

        };
    }
}
